/**
 * 购物车相关API
 * 根据接口文档实现购物车相关功能
 */

const request = require('../utils/request');

/**
 * 查看购物车
 * GET /user/shoppingCart/list
 * @returns {Promise} 购物车列表数据
 */
const getCartList = () => {
  return request.get('/user/shoppingCart/list');
};

/**
 * 添加购物车
 * POST /user/shoppingCart/add
 * @param {Object} params - 购物车参数
 * @param {string} params.dishFlavor - 口味
 * @param {number} params.dishId - 菜品id
 * @param {number} params.setmealId - 套餐id
 * @returns {Promise} 添加结果
 */
const addToCart = (params) => {
  return request.post('/user/shoppingCart/add', params);
};

/**
 * 删除购物车中一个商品
 * POST /user/shoppingCart/sub
 * @param {Object} params - 购物车参数
 * @param {string} params.dishFlavor - 口味
 * @param {number} params.dishId - 菜品id
 * @param {number} params.setmealId - 套餐id
 * @returns {Promise} 删除结果
 */
const removeFromCart = (params) => {
  return request.post('/user/shoppingCart/sub', params);
};

/**
 * 清空购物车
 * DELETE /user/shoppingCart/clean
 * @returns {Promise} 清空结果
 */
const clearCart = () => {
  return request.delete('/user/shoppingCart/clean');
};

module.exports = {
  getCartList,
  addToCart,
  removeFromCart,
  clearCart
};